# python -u pomodoro.py (-u = PYTHONUNBUFFERED)

from twisted.internet import reactor

def start_tick():
    reactor.callLater(1 * 60, tick_timeout)

def start_pomodoro(pomodoros):
    pomodoros += 1
    print 'Started pomodoro', pomodoros
    reactor.callLater(25 * 60, pomodoro_timeout, pomodoros)

def start_pause(pomodoros):
    if pomodoros % 4 == 0:
        print 'Started long pause'
        reactor.callLater(30 * 60, long_pause_timeout, pomodoros)
    else:
        print 'Started pause'
        reactor.callLater(5 * 60, pause_timeout, pomodoros)

def long_pause_timeout(pomodoros):
    print 'Finished long pause\a'
    start_pomodoro(pomodoros)

def pause_timeout(pomodoros):
    print 'Finished pause\a'
    start_pomodoro(pomodoros)

def pomodoro_timeout(pomodoros):
    print 'Finished pomodoro\a'
    start_pause(pomodoros)

def tick_timeout():
    print '.',
    start_tick()

start_pomodoro(0)
start_tick()
reactor.run()
